﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Display.CollectionsUI {
    import flash.events.*;
    import Engine.Managers.*;
    import Events.*;
    import Display.DialogUI.*;
    import org.aswing.*;
    import Classes.*;
    import Display.*;
    import Display.MarketUI.*;
    import Display.InventoryUI.*;
    import flash.text.*;
    import org.aswing.ext.*;
    import Display.aswingui.*;

    public class CollectionCell extends JPanel implements GridListCell {

        public static const COLLECTION_TITLE_FONT_SIZE:Number = 18;
        public static const COLLECTION_CELL_WIDTH:Number = CollectionCatalogUI.COLLECTIONS_TITLE_WIDTH;
        public static const COLLECTION_CELL_HEIGHT:Number = (Catalog.CARD_HEIGHT + 50);
        public static const COLLECTION_ITEMS_WIDTH:int = 450;
        public static const COLLECTION_REWARD_WIDTH:int = (COLLECTION_CELL_WIDTH - COLLECTION_ITEMS_WIDTH);

        protected var m_collection:Collection;
        protected var m_gridList:GridList;
        protected var m_index:int;
        protected var m_shelf:JPanel;
        protected var m_rewardPanel:JPanel;
        protected var m_tradeInButton:JButton;
        protected var m_initialized:Boolean = false;

        public function CollectionCell(_arg1:LayoutManager=null){
            super(new SoftBoxLayout(SoftBoxLayout.Y_AXIS, 0, SoftBoxLayout.CENTER));
            ASwingHelper.prepare(this);
        }
        public function setGridListCellStatus(_arg1:GridList, _arg2:Boolean, _arg3:int):void{
            this.m_gridList = _arg1;
            this.m_index = _arg3;
            this.m_gridList.setTileWidth(COLLECTION_CELL_WIDTH);
            this.m_gridList.setTileHeight(COLLECTION_CELL_HEIGHT);
        }
        public function setCellValue(_arg1):void{
            this.m_collection = _arg1;
            this.initializeCell();
        }
        public function getCellValue(){
            return (this.m_collection);
        }
        public function getCellComponent():Component{
            return (this);
        }
        protected function initializeCell():void{
            var _local1:JPanel = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.LEFT);
            var _local2:JPanel = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.TOP, -3);
            _local2.append(this.makeTitlePanel());
            _local2.append(this.makeItemsPanel());
            ASwingHelper.prepare(_local2);
            _local1.append(_local2);
            _local1.append(ASwingHelper.horizontalStrut(-4));
            _local1.append(this.makeInfoPanel());
            ASwingHelper.prepare(_local1);
            this.append(_local1);
            this.setPreferredWidth(COLLECTION_CELL_WIDTH);
            ASwingHelper.prepare(this);
            this.m_initialized = true;
        }
        protected function makeInfoPanel():JPanel{
            var _local1:JPanel = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.BOTTOM);
            var _local2:Number = TextFieldUtil.getLocaleFontSize(14, 12, [{
                locale:"de",
                size:14
            }, {
                locale:"es",
                size:14
            }]);
            this.m_tradeInButton = new CustomButton(ZLoc.t("Dialogs", "CollectionTradeInButton"), null, "GreenButtonUI");
            this.m_tradeInButton.setFont(ASwingHelper.makeFont(EmbeddedArt.TITLE_FONT, _local2));
            this.m_tradeInButton.setEnabled(this.m_collection.isReadyToTradeIn());
            this.m_tradeInButton.addEventListener(MouseEvent.MOUSE_UP, this.onTradeIn, false, 0, true);
            _local1.append(this.makeRewardPanel());
            _local1.append(this.m_tradeInButton);
            _local1.append(ASwingHelper.verticalStrut(30));
            _local1.setPreferredWidth(COLLECTION_REWARD_WIDTH);
            ASwingHelper.prepare(_local1);
            return (_local1);
        }
        protected function makeTitlePanel():JPanel{
            var _local1:JPanel = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.TOP);
            var _local2:JTextField = ASwingHelper.makeTextField(this.m_collection.localizedName, EmbeddedArt.DEFAULT_FONT_NAME_BOLD, COLLECTION_TITLE_FONT_SIZE, EmbeddedArt.darkBlueTextColor);
            _local1.append(_local2);
            return (_local1);
        }
        protected function makeItemsPanel():JPanel{
            var _local3:String;
            var _local4:Item;
            var _local1:Array = this.m_collection.getCollectableNames();
            var _local2:Array = new Array();
            for each (_local3 in _local1) {
                _local4 = Global.gameSettings.getItemByName(_local3);
                if (_local4){
                    _local2.push(_local4);
                };
            };
            this.m_shelf = new InventoryScrollingList(_local2, CollectableCellFactory, 0, 5, 1, true);
            this.m_shelf.setPreferredWidth(COLLECTION_ITEMS_WIDTH);
            ASwingHelper.prepare(this.m_shelf);
            return (this.m_shelf);
        }
        protected function makeRewardPanel():JPanel{
            var _local8:JTextField;
            var _local9:JTextField;
            var _local10:JTextField;
            var _local11:Object;
            var _local12:JTextField;
            var _local13:String;
            var _local14:String;
            var _local15:AssetPane;
            var _local16:String;
            var _local17:String;
            var _local18:AssetPane;
            var _local19:String;
            var _local20:String;
            var _local21:AssetPane;
            if (!this.m_rewardPanel){
                this.m_rewardPanel = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.CENTER);
            };
            var _local1:JPanel = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.CENTER);
            var _local2:JPanel = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.CENTER);
            var _local3:Number = 120;
            if (this.m_collection.rewardCoins){
                _local8 = ASwingHelper.makeTextField((ZLoc.t("Collections", "CollectionsRewardCoins", {coins:this.m_collection.rewardCoins}) + " "), EmbeddedArt.DEFAULT_FONT_NAME_BOLD, 12, 2645358);
                this.m_rewardPanel.append(_local8);
            };
            if (this.m_collection.rewardEnergy){
                _local9 = ASwingHelper.makeTextField((ZLoc.t("Collections", "CollectionsRewardEnergy", {energy:this.m_collection.rewardEnergy}) + " "), EmbeddedArt.DEFAULT_FONT_NAME_BOLD, 12, 2645358);
                this.m_rewardPanel.append(_local9);
            };
            if (this.m_collection.rewardXp){
                _local10 = ASwingHelper.makeTextField((ZLoc.t("Collections", "CollectionsRewardXP", {xp:this.m_collection.rewardXp}) + " "), EmbeddedArt.DEFAULT_FONT_NAME_BOLD, 12, 2645358);
                this.m_rewardPanel.append(_local10);
            };
            var _local4:Array = this.m_collection.rewardCommodities;
            if (((_local4) && ((_local4.length > 0)))){
                for each (_local11 in _local4) {
                    _local12 = ASwingHelper.makeTextField((((_local11.amount + " ") + ZLoc.t("Main", (("Commodity_" + _local11.name) + "_friendlyName"))) + " "), EmbeddedArt.DEFAULT_FONT_NAME_BOLD, 12, 2645358);
                    this.m_rewardPanel.append(_local12);
                };
            };
            var _local5:Array = this.m_collection.rewardCollectableNames;
            if (((_local5) && ((_local5.length > 0)))){
                for each (_local13 in _local5) {
                    _local14 = Global.gameSettings.getItemFriendlyName(_local13);
                    _local15 = ASwingHelper.makeMultilineText((_local14 + " "), _local3, EmbeddedArt.DEFAULT_FONT_NAME_BOLD, TextFormatAlign.LEFT, 12, 2645358);
                    this.m_rewardPanel.append(_local15);
                };
            };
            var _local6:Array = this.m_collection.rewardItemNames;
            if (((_local6) && ((_local6.length > 0)))){
                for each (_local16 in _local6) {
                    _local17 = Global.gameSettings.getItemFriendlyName(_local16);
                    _local18 = ASwingHelper.makeMultilineText((_local17 + " "), _local3, EmbeddedArt.DEFAULT_FONT_NAME_BOLD, TextFormatAlign.LEFT, 12, 2645358);
                    this.m_rewardPanel.append(_local18);
                };
            };
            var _local7:Array = this.m_collection.rewardUnlocks;
            if (((_local7) && ((_local7.length > 0)))){
                for each (_local19 in _local7) {
                    _local20 = ZLoc.t("Items", (_local19 + "_friendlyName"));
                    _local21 = ASwingHelper.makeMultilineText((_local20 + " "), _local3, EmbeddedArt.DEFAULT_FONT_NAME_BOLD, TextFormatAlign.LEFT, 12, 2645358);
                    this.m_rewardPanel.append(_local21);
                };
            };
            ASwingHelper.prepare(this.m_rewardPanel);
            return (this.m_rewardPanel);
        }
        protected function onTradeIn(_arg1:MouseEvent):void{
            if (((this.m_collection.isReadyToTradeIn()) && (this.m_tradeInButton.isEnabled()))){
                this.m_collection.tradeIn();
                this.invalidateData();
                this.showTradeInDialog();
            } else {
                UI.displayMessage("You must complete this collection to trade it in.");
            };
        }
        public function invalidateData():void{
            if (this.m_initialized){
                (this.m_shelf as InventoryScrollingList).updateElements();
                this.m_tradeInButton.setEnabled(this.m_collection.isReadyToTradeIn());
                this.m_rewardPanel.removeAll();
                this.makeRewardPanel();
                ASwingHelper.prepare(this);
            };
        }
        protected function showTradeInDialog():void{
            UI.displayMessage(ZLoc.t("Dialogs", "CollectionTradeInShare"), GenericDialogView.TYPE_SHARECOINS, this.postCollectionFeed);
        }
        protected function postCollectionFeed(_arg1:GenericPopupEvent):void{
            if (_arg1.button == GenericDialogView.YES){
                StatsManager.count("Share", "TradeIn");
                Global.world.viralMgr.sendCollectionTradeInFeed(Global.player, this.m_collection.localizedName);
            };
        }

    }
}//package Display.CollectionsUI 
